<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */


/**
 * Smarty number_format modifier plugin
 *
 * Type:     modifier<br>
 * Name:     number_format<br>
 * Purpose:  format number via number_format
 * @link http://smarty.php.net/manual/en/language.modifier.number.format.php
 *          number_format (Smarty online manual)
 * @author   Dmytro Bezhnar <demonister at gmail dot com>
 * @param string
 * @param  string EUR USD UAH
 * @param  boolean
 * @param string
 * @return string
 */
function smarty_modifier_price_format($string, $quote='USD',$whithout_cent=true,$text = '')
{
    $number = 0;
    if ($whithout_cent){
        $number = number_format($string, 0, '', ' ');
    }else{
        $number = number_format($string, 2, ',', ' ');
    }
    
    $quote = strtolower($quote);
    switch($quote){
        case 'eur':
        case '2':
            if ($text==''){$text='€ ';}
            $number = $text.$number;
        break;
        case 'usd':
        case '1':
            if ($text==''){$text='$ ';}
            $number = $text.$number;
        break;
        case 'uah':
        case '3':
            if ($text==''){$text=' грн.';}
            $number = $number.$text;
        break;
    }
    return $number;
}

/* vim: set expandtab: */

?>
